package cn.andy.android.crm;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.TabHost;
import cn.andy.android.crm.common.Util;

public class FrameworkActivity extends FragmentActivity {

	private static String TAG = "cn.andy.android.crm.FrameworkActivity";

	/**
	 * Called when the activity is first created.
	 * 
	 * @param savedInstanceState
	 *            If the activity is being re-initialized after previously being
	 *            shut down then this Bundle contains the data it most recently
	 *            supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it
	 *            is null.</b>
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if (BuildConfig.DEBUG) {
			Log.i(TAG, "onCreate");
		}

		init();
//		new LoadViewTask().execute();

	}

	private void init() {
		Util.initLocalization(this);

		setContentView(R.layout.main);

		TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);

		tabHost.setup();

//		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_home_key))
//				.setIndicator(getString(R.string.tab_home_title))
//				.setContent(R.id.tabHome));
//		
//		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_profile_key))
//				.setIndicator(getString(R.string.tab_profile_title))
//				.setContent(R.id.tabProfile));
//
//		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_settings_key))
//				.setIndicator(getString(R.string.tab_settings_title))
//				.setContent(R.id.tabSettings));
		
		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_sqlitedemo_key))
				.setIndicator(getString(R.string.tab_sqlitedemo_title))
				.setContent(R.id.tabSqliteDemo));
		
		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_mapdemo_key))
				.setIndicator(getString(R.string.tab_mapdemo_title))
				.setContent(R.id.tabMapDemo));

		tabHost.addTab(tabHost.newTabSpec(getString(R.string.tab_shakedemo_key))
				.setIndicator(getString(R.string.tab_shakedemo_title))
				.setContent(R.id.tabShakeDemo));

	}

	private class LoadViewTask extends AsyncTask<Void, Integer, Void> {

		@Override
		protected void onPreExecute() {
			setContentView(R.layout.loading);
			setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
		}

		@Override
		protected Void doInBackground(Void... params) {
			try {
				// Get the current thread's token
				synchronized (this) {
					this.wait(3350);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			init();
		}

	}

}
